

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gczn_hd/app/core/widget/custom_title_bar.dart';

import '../../../../core/values/App_img.dart';
import '../../../../core/values/app_colors.dart';
import '../../../../core/values/app_values.dart';
import '../../../../core/values/text_styles.dart';

class FormRight extends StatelessWidget{

  @override
  Widget build(BuildContext context) {

    return Column(
      children: [
        CustomTitleBar(title: "报工录入", handleBtn: Row(
          children: [
            Text("自动计数差：322", style: textStyle20Opa8,),
            SizedBox(width: AppValues.size108.w,),
            Text("本次良品统计：300", style: textStyle20Opa8,),
          ],
        ),),
        Expanded(
          flex: 1,
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(height: AppValues.size30.h,),
                _buildCounter(title: '本次报工数量'),
                SizedBox(height: AppValues.size30.h,),
                _buildCounter(title: '本次不良品数量'),
                SizedBox(height: AppValues.size30.h,),
                _buildBadList(context), // 不良品输入
                SizedBox(height: AppValues.size30.h,),
                _buildUpload(),
                SizedBox(height: AppValues.size30.h,),
                _buildRemark()
              ],
            ),
          )
        )
      ],
    );
  }

  Widget _buildRemark(){
    return Container(
      padding:  EdgeInsets.symmetric(horizontal: AppValues.size20.w),
      alignment: Alignment.topLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text("备注", style: textStyle,),
          SizedBox(height: AppValues.size20.h,),
          Container(
            width: double.infinity,
            height: AppValues.size100.h,
            padding: EdgeInsets.symmetric(vertical: AppValues.margin_10.w, horizontal: AppValues.margin_10.h),
            decoration: const BoxDecoration(
              color: AppColors.gcznPrimaryColor
            ),
            child: Text("data", style: textStyle,),
          )
        ],
      ),
    );
  }

  /// 上传
  Widget _buildUpload(){

    return Container(
      padding:EdgeInsets.symmetric(horizontal: AppValues.size20.w),
      alignment: Alignment.topLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text("品质图片", style: textStyle,),
          SizedBox(height: AppValues.size20.h,),
          Wrap(
            spacing: AppValues.margin_10.w, // 水平间距
            runSpacing: AppValues.margin_10.h, // 垂直间距
            children: [
              ..._buildImageList(),
            ],
          )
        ],
      ),
    );

  }

  /// 上传图片列表
  List<Widget> _buildImageList(){
    List<Widget> list = [];
    list = [1,2,3,4].map((item) => Stack(
      clipBehavior: Clip.none, // 禁用裁剪
      children: [
        Container(
          width: AppValues.size100.w,
          height: AppValues.size100.w,
          decoration: BoxDecoration(
            color: AppColors.counterBtn,
            borderRadius: BorderRadius.circular(AppValues.margin_12.r),
          ),
          child: Center(
            child: Image.asset(AppImg.defaultpic, fit: BoxFit.fill,),
          ),
        ),
      ],
    )).toList();


    return list;
  }

  /// 不良品列表
  Widget _buildBadList(BuildContext context){

    return Container(
      padding:  EdgeInsets.symmetric(horizontal: AppValues.size20.w),
      alignment: Alignment.topLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text("不良品项", style: textStyle,),
          SizedBox(height: AppValues.size20.h,),
          Wrap(
            spacing: AppValues.margin_10.w, // 水平间距
            runSpacing: AppValues.margin_10.h, // 垂直间距
            children: [
              _buildBadItem(text: "未收紧 1.0"),
              _buildBadItem(text: "未收紧 1.0"),
            ],
          )
        ],
      ),
    );
  }

  /// 不良品项
  Widget _buildBadItem({required text}){

    return  Container(

      padding: EdgeInsets.only(left: AppValues.size28.w, right: AppValues.size28.w, top: AppValues.size12.w, bottom: AppValues.size12.w),
      decoration: BoxDecoration(
        color:AppColors.badBg,
        borderRadius: BorderRadius.circular(AppValues.margin_12.r),
      ),
      child: Text(text, style: textStyle,),
    );
  }


  Widget _buildCounter({required String title}){
    const double inputWidth = 200;
    
    

    return  Container(
      padding:  EdgeInsets.symmetric(horizontal: AppValues.size20.w),
      margin: EdgeInsets.only(top: AppValues.size20.h),
      alignment: Alignment.topLeft,
      child: Column(
        children: [
          Text(title, style: textStyle,),
          Container(
            margin: EdgeInsets.only(top: AppValues.size12.h),
            width: inputWidth.w,
            height:AppValues.size86.h,
            padding: const EdgeInsets.all(2),
            decoration: BoxDecoration(
              color: AppColors.gcznPrimaryColor,
                border: Border.all(color: AppColors.counterBtn)
            ),
            child: Center(
              child: Text("100", style: textStyle30,),
            ),
          )
        ],
      ),
    );
  }

}